package com.ssm.supplier.controller;

import com.ssm.common.utils.PageUtils;
import com.ssm.common.utils.R;
import com.ssm.supplier.entity.SsmSudetailsEntity;
import com.ssm.supplier.entity.vo.SudetailsDto;
import com.ssm.supplier.entity.vo.SupplierGoodsVo;
import com.ssm.supplier.entity.vo.SupplierOrderDetailsVo;
import com.ssm.supplier.service.SsmSudetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author ssm
 * @email sunlightcs@gmail.com
 * @date 2023-03-19 17:27:39
 */
@RestController
@RequestMapping("supplier/ssmsudetails")
public class SsmSudetailsController {
    @Autowired
    private SsmSudetailsService ssmSudetailsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = ssmSudetailsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
//		SsmSudetailsEntity ssmSudetails = ssmSudetailsService.getById(id);
        List<SudetailsDto> sudetailsDto = ssmSudetailsService.getorder(id);
        return R.ok().put("sudetailsDto", sudetailsDto);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SsmSudetailsEntity ssmSudetails){
		ssmSudetailsService.save(ssmSudetails);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SsmSudetailsEntity ssmSudetails){
		ssmSudetailsService.updateById(ssmSudetails);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		ssmSudetailsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 供货端获取补货订单详情
     */
    @GetMapping("findSuDetails/{id}")
    public R findSuDetails(@PathVariable String id){
        List<SupplierOrderDetailsVo> detailsVoList = ssmSudetailsService.findSupplierDetailsById(id);
        return R.ok().put("detailsVoList",detailsVoList);
    }

    /**
     * 供货端删除订单详情
     */
    @DeleteMapping("deleteOrderInfo/{id}")
    public R deleteOrderInfo(@PathVariable Integer id){
        ssmSudetailsService.deleteSuOrderInfoById(id);
        return R.ok();
    }

    /**
     * 根据id查询供货端商品信息
     */
    @GetMapping("findGoodsById/{id}")
    public R findGoodsById(@PathVariable Integer id){
        List<SupplierGoodsVo> goodsVoList = ssmSudetailsService.findGoodsById(id);
        return R.ok().put("goodsVoList",goodsVoList);
    }
    /**
     * 供货端根据id查询订单
     */
    @GetMapping("findDetailsInfo/{id}")
    public R findDetailsInfo(@PathVariable Integer id){
        SsmSudetailsEntity ssmSudetails = ssmSudetailsService.getById(id);
        return R.ok().put("ssmSudetails", ssmSudetails);

    }

    /**
     * 供货端订单修改
     */
    @PutMapping("updateSupplierInfo")
    public R updateSupplierInfo(@RequestBody List<SsmSudetailsEntity> ssmSudetails){
        ssmSudetailsService.updateBatchById(ssmSudetails);

        return R.ok();
    }
    /**
     * 供货端订单增加
     */
    @PostMapping("saveSupplierInfo")
    public R saveSupplierInfo(@RequestBody List<SsmSudetailsEntity> ssmSudetails){
        ssmSudetailsService.saveBatch(ssmSudetails);
        return R.ok();
    }


}
